home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2569 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. From: zodiac@darkness.gun.de (Ralph Seichter)
  2. Subject: SAS/C fopen("foo","a") -- is this a bug?
  3. Date: Wed, 31 Jan 96 17:51:42 CET
  4. Message-ID: <zpfaa8aCCygGZ1@da23.darkness.gun.de>
  5. X-ZC-PGP-KEY-AVAIL: 
  6. Path: tim.xenologics.com!darkness.gun.de
  7. X-ZC-Telefon: V+49-2667-969000Q
  8. X-Newsreader: Zodiac's Point 37.207 [REGISTERED 0001] via Connectline-CLMSortin 2.25
  9. Newsgroups: comp.sys.amiga.programmer
  10. X-Gateway: ZConnect DA darkness.gun.de [Connectline/AmigaOS]
  11.  
  12. I used the following test program:
  13.  
  14. ----------8<----------8<----------8<----------8<----------8<----------
  15. /* test.c */
  16.  
  17. #include <stdio.h>
  18.  
  19. void main(void)
  20. {
  21.     FILE *file;
  22.  
  23.     if (file = fopen("foo", "w"))
  24.     {
  25.         if (fprintf(file, "bar", 3) == 3)
  26.             printf("write ok\n");
  27.         fclose(file);
  28.     }
  29.  
  30.     if (file = fopen("foo", "a"))
  31.     {
  32.         if (fprintf(file, "bar", 3) == 3)
  33.             printf("append ok\n");
  34.         fclose(file);
  35.     }
  36. }
  37. ----------8<----------8<----------8<----------8<----------8<----------
  38.  
  39. After I compiled this with SAS/C 6.56, I did the following in a shell:
  40.  
  41.    1> sc link test.c
  42.    1> date >foo
  43.    1> protect foo r
  44.    1> test
  45.    append ok
  46.  
  47. The first fopen() with mode "w" fails, which is correct. But why can the
  48. write-protected file "foo" be opened with mode "a", and why won't fprintf()
  49. return an error? The file's contents are not changed, as is to be expected,
  50. but fprintf() reports that three bytes were written, which is not true.
  51.  
  52.     -Ralph
  53. -- 
  54. "Ja Ja!! Ich bin ein trottel !!!" (Nils G÷rs)
  55.